'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM } = Sequelize;
    
    await queryInterface.createTable('contracts', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      contractNumber: {
        type: STRING(50),
        allowNull: false,
        unique: true,
        comment: '合同编号'
      },
      supplierId: {
        type: INTEGER,
        allowNull: false,
        comment: '供应商ID'
      },
      contractName: {
        type: STRING(200),
        allowNull: false,
        comment: '合同名称'
      },
      contractType: {
        type: ENUM('purchase', 'service', 'other'),
        defaultValue: 'purchase',
        comment: '合同类型: purchase(采购合同), service(服务合同), other(其他)'
      },
      startDate: {
        type: DATE,
        allowNull: false,
        comment: '合同开始日期'
      },
      endDate: {
        type: DATE,
        allowNull: false,
        comment: '合同结束日期'
      },
      amount: {
        type: DECIMAL(15, 2),
        allowNull: false,
        comment: '合同金额'
      },
      status: {
        type: ENUM('active', 'expired', 'terminated'),
        defaultValue: 'active',
        comment: '合同状态: active(生效中), expired(已过期), terminated(已终止)'
      },
      attachment: {
        type: STRING(500),
        allowNull: true,
        comment: '合同附件路径'
      },
      remark: {
        type: TEXT,
        allowNull: true,
        comment: '备注'
      },
      createdAt: {
        type: DATE,
        allowNull: false,
        defaultValue: new Date()
      },
      updatedAt: {
        type: DATE,
        allowNull: false,
        defaultValue: new Date()
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('contracts');
  }
};